<template>
    <div id="createsettlement">
        <el-dialog
        title="创建结算单"
        :visible.sync="dialogVisible"
        class=''
        top="10vh"
        :close-on-click-modal="false"
        :before-close="handleClose"
        >
            <el-form v-model="formData" label-width="120px" label-position="left">
                <el-form-item label="选择结算周期:">
                    <el-select  size="small" v-model="formData.time" placeholder="请选择结算周期" clearable filterable style="margin-right: 30px">  
                        <el-option
                            v-for="item in weeksArray"
                            :key="item.firstDay"
                            :label="'第' +item.weekth + '周'"
                            :value="JSON.stringify(item)">
                            <span style="float: left">{{ '第' +item.weekth + '周'}}</span>
                            <span style="float: right; color: #8492a6; font-size: 13px">{{ item.firstDay + '~' + item.seventhDay }}</span>
                        </el-option> 
                    </el-select>
                </el-form-item>
                <el-form-item label="选择门店类型:">
                    <el-select size="small" v-model="formData.storeType">
                        <el-option v-for="(item, index) in $Options.storeTypes=$Options.storeType" :label="item.label" :value='item.value' :key="index"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button size="small" @click="handleClose">取 消</el-button>
                <el-button size="small" type="primary" @click="handleSubmit">提交保存</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script>

    export default {
        props: ['isShow', 'weeksArray'],
        data() {
            return {
                userInfo: JSON.parse(sessionStorage.getItem('userInfo')),
                formData: {
                    time: '',
                    storeType: 1
                },
               
            }
        },
        computed: {
            dialogVisible: {
                get() {
                    return this.isShow;
                },
                set() {}
            }
        },
        mounted() {
            
        },
        methods: {
            handleClose() {
                this.$confirm('确认关闭？').then(_ => {
                    this.$emit('cancelShow', false)
                }).catch(_ => {});
            },
            handleSubmit() {
                if(this.formData.time != '') {
                    let time= JSON.parse(this.formData.time)
                    let params= {
                        createUser: this.userInfo.personName,
                        createUserId: this.userInfo.userId,
                        storeType: this.formData.storeType,
                        gmtStart: this.formate(new Date(time.firstDay).getTime(), 'yyyy-MM-dd 00:00:00'),
                        gmtEnd: this.formate(new Date(time.seventhDay).getTime(), 'yyyy-MM-dd 23:59:59'),
                        settleOrderId: ''+time.yearth +(time.weekth <10 ? '0'+ time.weekth :  ''+time.weekth)
                    }
                    this.$server.financialControlApi.createSettlement(params).then(res => {
                        this.$emit('cancelShow', false)
                        this.$emit('getStoreSettlementList')
                    })
                }else{
                    this.$message({
                        message: '请选择结算周期',
                        type: 'error',
                        duration: 1500
                    })
                }
            }
        }
    }
</script>